<template>
  <div>
    <div class="bread" style="margin-bottom: 30px;">
      <el-breadcrumb separator-class="el-icon-arrow-right">
        <el-breadcrumb-item :to="{ path: '#' }" style="font-size: 20px;"
          >首页</el-breadcrumb-item
        >
        <el-breadcrumb-item style="font-size: 20px;"
          >订单管理</el-breadcrumb-item
        >
        <el-breadcrumb-item style="font-size: 20px;"
          >全部订单</el-breadcrumb-item
        >
      </el-breadcrumb>
    </div>

    <el-row style="margin-top: 30px;">
      <el-col style="margin-left:50px;" :span="2" :offset="0">
        <el-select
          @change="listOrders"
          v-model="orderState"
          clearable
          placeholder="订单状态"
        >
          <el-option
            v-for="item in options"
            :key="item.state"
            :label="item.label"
            :value="item.state"
          >
          </el-option>
        </el-select>
      </el-col>
    </el-row>

    <div ref="table">
      <el-table
        :data="page.list"
        border
        style="width: 1411px;margin-left: 50px;margin-top: 20px;"
        :stripe="true"
        :header-cell-style="{ 'text-align': 'center' }"
        :cell-style="{ 'text-align': 'center' }"
      >
        <el-table-column prop="orderNum" label="订单编号" width="180">
        </el-table-column>
        <el-table-column prop="addressInfo" label="地址" width="300">
        </el-table-column>
        <el-table-column prop="receiverName" label="收货人" width="100">
        </el-table-column>
        <el-table-column prop="receiverPhone" label="收货电话" width="150">
        </el-table-column>
        <el-table-column prop="orderPrice" label="订单价格" width="150">
        </el-table-column>
        <el-table-column prop="createTime" label="创建时间" width="230">
          <template slot-scope="scope">
            <span>{{
              scope.row.createTime
                .toLocaleString()
                .replace(/T/g, " ")
                .replace(/\.[\d]{3}Z/, "")
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          prop="payTime"
          label="付款时间"
          width="200"
        >
          <template slot-scope="scope">
            <span>{{
              scope.row.payTime == null
                ? ""
                : scope.row.payTime
                    .toLocaleString()
                    .replace(/T/g, " ")
                    .replace(/\.[\d]{3}Z/, "")
            }}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="订单状态" width="150">
          <template slot-scope="scope">
            <span v-if="scope.row.orderState == 0"
              >待支付<i style="color:chocolate;" class="el-icon-warning"></i
            ></span>
            <span v-if="scope.row.orderState == 1"
              >已支付<i style="color: limegreen;" class="el-icon-success"></i
            ></span>
            <span v-if="scope.row.orderState == 7"
              >已删除<i style="color: red;" class="el-icon-delete-solid"></i
            ></span>
            <span v-if="scope.row.orderState == 2"
              >已取消<i style="color:chocolate;" class="el-icon-error"></i
            ></span>
            <span v-if="scope.row.orderState == 4"
              >待处理<i style="color:chocolate;" class="el-icon-warning"></i
            ></span>
            <span v-if="scope.row.orderState == 5"
              >退款中<i style="color:chocolate;" class="el-icon-warning"></i
            ></span>
            <span v-if="scope.row.orderState == 6"
              >退款成功<i style="color: limegreen;" class="el-icon-success"></i
            ></span>
            <span v-if="scope.row.orderState == 8"
              >退款申请被驳回<i style="color:chocolate;" class="el-icon-warning"></i
            ></span>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-row style="margin-left: 50px;">
      <el-col :span="5">
        <el-pagination
          @size-change="pageSizeChange"
          @current-change="pageNumChange"
          :current-page="page.current"
          :page-sizes="[1, 5, 10]"
          :page-size="page.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="page.total"
        >
        </el-pagination>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data() {
    return {
      page: {},
      orderState: null,
      options: [
        {
          state: "0",
          label: "待支付"
        },
        {
          state: "1",
          label: "已支付"
        },
        {
          state: "2",
          label: "已取消"
        },
        {
          state: "7",
          label: "已删除"
        },
        {
          state:"4",
          label:"待处理"
        },
        {
          state:"5",
          label:"退款中"
        },
        {
          state:"6",
          label:"退款成功"
        },
        {
          state:"8",
          label:"退款申请被驳回"
        }
      ]
    };
  },
  methods: {
    pageSizeChange(size) {
      this.page.current = 1;
      this.splitePage(this.page.current, size);
    },
    pageNumChange(current) {
      this.splitePage(current, this.page.size);
    },
    listOrders() {
      //查找全部
      //调用分页函数
      this.splitePage(this.page.current, this.page.size);
    },
    splitePage(pageNum, pageSize) {
      this.$http
        .get("/orderInfo/admin/selectOrders", {
          params: {
            pageNum: pageNum,
            pageSize: pageSize,
            orderState: this.orderState
          }
        })
        .then(resp => {
          console.log(resp.data.data);
          //将分页信息传入data区中
          this.page = resp.data.data;
        });
    },
    showSingleOrder(item) {
      sessionStorage.setItem("singleOrder", JSON.stringify(item));
      this.$router.push("/showSingleOrder");
    }
  },
  created() {
    this.listOrders();
  }
};
</script>

<style scoped>
@import "../../assets/login/css/style.css";
@import "../../assets/bootstrap-3.3.4/dist/css/bootstrap.min.css";
@import "../../assets/Flat-UI-master/dist/css/flat-ui.min.css";
.row {
  margin-left: 20px;
  margin-right: 20px;
}

.line-center {
  line-height: 50px;
  text-align: center;
}

.row input {
  width: 50px;
}

.list-group-item:hover {
  background: #27ae60;
}

.list-group-item div:first-child:hover {
  cursor: pointer;
}

.bread {
  margin-top: 50px;
  margin-left: 50px;
}
</style>
